import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
  current_page: number;
  result?: any;
  per_page?: number;
  total?: number;
};
type ResultDelete = {
  code: number;
  message: string;
};
type ResultCreate = {
  code: number;
  message: string;
};
type Show = {
  code: number;
  message: string;
  result?: any;
};

/**
 *
 * 客户API
 * 增删改查
 *
*/

/** 列表 */
export const customerListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/customer/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 添加 */
export const customerStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/customer/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 编辑 */
export const customerUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/customer/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 详情 */
export const customerShowApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/customer/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 删除 */
export const customerDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/customer/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 选择 */
export const customerSelectApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/customer/select", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
